#include <QCoreApplication>
#include "ctkPluginFrameworkFactory.h"
#include "ctkPluginFramework.h"
#include "ctkPluginException.h"
#include "ctkPlugin.h"
#include "ctkPluginContext.h"

#include <QDebug>
int main(int argc, char* argv[])
{
    QCoreApplication app(argc, argv);
    app.setApplicationName("SampleCTK");
    ctkPluginFrameworkFactory frameWorkFactory;
    QSharedPointer<ctkPluginFramework> framework = frameWorkFactory.getFramework();
    try {
        framework->init();
        framework->start();
        qDebug() << "CTK Plugin Framework start ...";

        QString dir = QCoreApplication::applicationDirPath();
        dir += "/plugins/ImageLoaderModel.dll";
        qDebug() << dir;
        QUrl url = QUrl::fromLocalFile(dir);
        QSharedPointer<ctkPlugin> plugin;
        try
        {
            plugin = framework->getPluginContext()->installPlugin(url);
        }
        catch (ctkPluginException e) {
            qDebug() << e.message() << e.getType();
        }
        try {
            plugin->start(ctkPlugin::START_TRANSIENT);
        }
        catch (ctkPluginException e) {
            qDebug() << e.message() << e.getType();
        }

    }
    catch (const ctkPluginException& e) {
        qDebug() << "Failed to initialize the plugin framework: " << e.what();
        qDebug() << e.message() << e.getType();
    }
    return app.exec();
}
